console.log('\x1b[31mconcat\x1b[0m');
let 数组 = ['1', '2', '3'];
数组 = 数组.concat('a', 'b', 'c');
console.log(数组);


console.log('\x1b[31mjoin\x1b[0m');
数组 = ['风', '雨', '晴'];
console.log(数组.join('-'));


console.log('\x1b[31mpush\x1b[0m');
数组 = ['1', '2'];
console.log(数组.push('3'));
console.log(数组);


console.log('\x1b[31mpop\x1b[0m');
数组 = ['1', '2', '3'];
console.log(数组.pop());
console.log(数组);


console.log('\x1b[31mshift\x1b[0m');
数组 = ['1', '2', '3'];
console.log(数组.shift());
console.log(数组);


console.log('\x1b[31munshift\x1b[0m');
数组 = ['1', '2', '3'];
数组.unshift('4', '5');
console.log(数组);


console.log('\x1b[31mslice\x1b[0m');
数组 = ['a', 'b', 'c', 'd', 'e'];
console.log(数组.slice(1, 4));


console.log('\x1b[31mat\x1b[0m');
数组 = ['a', 'b', 'c', 'd', 'e'];
console.log(数组.at(-2));


console.log('\x1b[31msplice\x1b[0m');
数组 = ['1', '2', '3', '4', '5'];
console.log(数组.splice(1, 3, 'a', 'b', 'c', 'd'));
console.log(数组);


console.log('\x1b[31mreverse\x1b[0m');
数组 = ['1', '2', '3'];
console.log(数组.reverse());
console.log(数组);


console.log('\x1b[31mflat\x1b[0m');
数组 = [1, 2, [3, 4]];
console.log(数组.flat());
console.log(数组);


console.log('\x1b[31msort\x1b[0m');
数组 = ['风', '雨', '晴'];
console.log(数组.sort());
console.log(数组);

console.log('----------------');

数组 = ["Wind", "Rain", "Fire"];
const 排序函数 = (a, b) => {
    if (a[a.length - 1] < b[b.length -1]) {
        return -1;
    }
    else if (a[a.length - 1] > b[b.length - 1]) {
        return 1;
    }
    return 0;
}
数组.sort(排序函数);
console.log(数组);


console.log('\x1b[31mindexOf\x1b[0m');
数组 = ['a', 'b', 'a', 'b', 'a'];
console.log(数组.indexOf('b'));
console.log(数组.indexOf('z'));


console.log('\x1b[31mlastIndexOf\x1b[0m');
数组 = ['a', 'b', 'c', 'd', 'a', 'b'];
console.log(数组.lastIndexOf('b'));
console.log(数组.lastIndexOf('b', 4));
console.log(数组.lastIndexOf('z'));


console.log('\x1b[31mforEach\x1b[0m');
数组 = ['a', 'b', 'c'];
数组.forEach(
    (元素) => console.log(元素)
);


console.log('\x1b[31mmap\x1b[0m');
数组 = ['a', 'b', 'c'];
let 数组2 = 数组.map(
    (元素) => 元素.toUpperCase()
);
console.log(数组2);


console.log('\x1b[31mflatMap\x1b[0m');
数组 = ['a', 'b', 'c'];
数组2 = 数组.flatMap(
    (元素) => [元素.toUpperCase(), 元素.toLowerCase()]
);
console.log(数组2);


console.log('\x1b[31mfileter\x1b[0m');
数组 = ['a', 10, 'b', 20, 'c', 30];
数组2 = 数组.filter(
    (元素) => typeof 元素 === 'number'
);
console.log(数组2);


console.log('\x1b[31mfind\x1b[0m');
数组 = ['a', 10, 'b', 20, 'c', 30];
console.log(数组.find(
    (元素) => typeof 元素 === 'number'
));
console.log(数组.findLast(
    (元素) => typeof 元素 === 'number'
));
console.log(数组.findIndex(
    (元素) => typeof 元素 === 'number'
));
console.log(数组.findLastIndex(
    (元素) => typeof 元素 === 'number'
));


console.log('\x1b[31mevery\x1b[0m');
function 数字检验(值) {
    return typeof 值 === 'number';
}
数组 = [1, 2, 3];
console.log(数组.every(数字检验));
数组 = [1, '2', 3];
console.log(数组.every(数字检验));


console.log('\x1b[31msome\x1b[0m');
数组 = [1, 2, 3];
console.log(数组.some(数字检验));
数组 = [1, '2', 3];
console.log(数组.some(数字检验));


console.log('\x1b[31mreduce\x1b[0m');
数组 = [10, 20 ,30];
let 累计 = 数组.reduce(
    (累加, 当前) => 累加 + 当前, 0,
);
console.log(累计);